package util;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.io.Serializable;
import processing.CalculateScore;

public class Query implements Serializable {
	
	private String name;
	private List<String> tokens;
	
	public Query(String name, List<String> tokens) {
		this.name = name;
		this.tokens = tokens;
	}
	
	public Query() {
		this.tokens = new ArrayList<String>();
	}

	public void addToken(String token) {
		this.tokens.add(token);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<String> getTokens() {
		return tokens;
	}

	public void setTokens(List<String> tokens) {
		this.tokens = tokens;
	}
	
	public Hashtable<String,Integer> getTokensWifHash(InvertedIndex invIndex){
		List<String> tokenList = new ArrayList<String>();
		List<Integer> tfList = new ArrayList<>();
		List<Integer> idfList = new ArrayList<>();
		Integer tfAux = 0;
		Integer maxTf = 0;
		
		for (String s : this.getTokens() ){
		tfAux = 0; 
			
		if (!tokenList.contains(s)){
			
			for (String s2 : this.getTokens()){
				if (s == s2) tfAux++;
				
			}
		}
		
		if (maxTf < tfAux) maxTf = tfAux;
		
		tokenList.add(s);
		tfList.add(tfAux);
		
		}
		
		
		for (String s : invIndex.getListOfTerms()){
			if (tokenList.contains(s)){
				idfList.add(invIndex.getEntry(s).getIdf());
			}
		}

		Hashtable<String,Integer> TermsWithWif = new Hashtable<String,Integer>();
		int aux = -1;
		
		for (String s : tokenList){
			aux++;
			
			int weight = (tfList.get(0)/maxTf) * idfList.get(0) ;
			
			
			TermsWithWif.put(s,weight );
		}
		
		return TermsWithWif;
	}
	

}
